from django.contrib.auth.models import Permission, Group
from django.contrib.contenttypes.models import ContentType
from rest_framework.generics import ListAPIView
from rest_framework.viewsets import ModelViewSet

from apps.meiduo_admin.serializers.permission import PermissionModelSerializer, ContentTypeModelSerializer, \
    GroupSerialzier, AdminSerializer
from apps.meiduo_admin.utils import PageNum
from apps.users.models import User


class PermissionModelViewSet(ModelViewSet):
    # 1指定查询集
    queryset = Permission.objects.all().order_by("id")
    # 2指定序列化器
    serializer_class = PermissionModelSerializer

    # 添加分页类
    pagination_class = PageNum


class ContentTypeListAPIView(ListAPIView):
    # 1指定查询集
    queryset = ContentType.objects.all()
    # 2指定序列化器
    serializer_class = ContentTypeModelSerializer


# 组的视图
class GroupView(ModelViewSet):
    serializer_class = GroupSerialzier
    queryset = Group.objects.all()
    pagination_class = PageNum


# 获取所有权限 用来添加组
class PermissionSimpleAPIView(ListAPIView):
    queryset = Permission.objects.all()

    serializer_class = PermissionModelSerializer


# 管理员 视图
class AdminView(ModelViewSet):
    serializer_class = AdminSerializer
    # 获取管理员用户
    queryset = User.objects.filter(is_staff=True)

    pagination_class = PageNum


# 獲取所有的組  用來添加管理員
class GroupSimpleAPIView(ListAPIView):
    queryset = Group.objects.all()

    serializer_class = GroupSerialzier
